🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / settings / src / jvmMain / kotlin / org / meshtastic / feature / settings / debugging / LogExporter.kt
Displaying Raw • Download
feature/settings/src/jvmMain/kotlin/org/meshtastic/feature/settings/debugging/LogExporter.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 3.00 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.settings.debugging
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.runtime.rememberCoroutineScope
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787kotlinx.coroutines.withContext
Tff7b72import T7ee787org.meshtastic.core.common.log.InMemoryLogBuffer
Tff7b72import T7ee787org.meshtastic.core.common.util.ioDispatcher
Tff7b72import T7ee787java.awt.FileDialog
Tff7b72import T7ee787java.awt.Frame
Tff7b72import T7ee787java.io.File
Tff7b72import T7ee787java.io.FileOutputStream
Tff7b72import T7ee787java.io.OutputStreamWriter
Tff7b72import T7ee787java.nio.charset.StandardCharsets
Tf0883e@Composable
Tff7b72actual Tff7b72fun Td2a8ffrememberLogExporterTb4b4b4(Te6edf3contentProviderTb4b4b4: Te6edf3suspend Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657StringTb4b4b4)Tb4b4b4: Tb4b4b4(Te6edf3fileNameTb4b4b4: Tffa657StringTb4b4b4) Tff7b72-Tff7b72> Tffa657Unit Tb4b4b4{
Tff7b72val Te6edf3scope Tff7b72= Te6edf3rememberCoroutineScopeTb4b4b4(Tb4b4b4)
Tff7b72return Tb4b4b4{ Te6edf3fileName Tff7b72-Tff7b72>
Te6edf3scopeTb4b4b4.Te6edf3launch Tb4b4b4{
Tff7b72val Te6edf3content Tff7b72= Te6edf3contentProviderTb4b4b4(Tb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3contentTb4b4b4.Te6edf3isBlankTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3w Tb4b4b4{ Ta5d6ff"Ta5d6ffLog export aborted: no contentTa5d6ff" Tb4b4b4}
Tff7b72returnTf0883e@launch
Tb4b4b4}
Te6edf3withContextTb4b4b4(Te6edf3ioDispatcherTb4b4b4) Tb4b4b4{
T8b949e// Run file dialog to ask user where to save
Tff7b72val Te6edf3fileDialog Tff7b72= Te6edf3FileDialogTb4b4b4(Tff7b72null Tff7b72as Te6edf3Frame?Tb4b4b4, Ta5d6ff"Ta5d6ffExport LogsTa5d6ff"Tb4b4b4, Te6edf3FileDialogTb4b4b4.Te6edf3SAVETb4b4b4)
Te6edf3fileDialogTb4b4b4.Te6edf3file Tff7b72= Te6edf3fileName
Te6edf3fileDialogTb4b4b4.Te6edf3isVisible Tff7b72= Tff7b72true
Tff7b72val Te6edf3directory Tff7b72= Te6edf3fileDialogTb4b4b4.Te6edf3directory
Tff7b72val Te6edf3selectedFile Tff7b72= Te6edf3fileDialogTb4b4b4.Te6edf3file
Tff7b72if Tb4b4b4(Te6edf3directory Tff7b72!Tff7b72= Tff7b72null Tff7b72&Tff7b72& Te6edf3selectedFile Tff7b72!Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3exportFile Tff7b72= Te6edf3FileTb4b4b4(Te6edf3directoryTb4b4b4, Te6edf3selectedFileTb4b4b4)
Tff7b72try Tb4b4b4{
Te6edf3FileOutputStreamTb4b4b4(Te6edf3exportFileTb4b4b4)Tb4b4b4.Te6edf3use Tb4b4b4{ Te6edf3fos Tff7b72-Tff7b72>
Te6edf3OutputStreamWriterTb4b4b4(Te6edf3fosTb4b4b4, Te6edf3StandardCharsetsTb4b4b4.Te6edf3UTF_8Tb4b4b4)Tb4b4b4.Te6edf3use Tb4b4b4{ Te6edf3writer Tff7b72-Tff7b72> Te6edf3writerTb4b4b4.Te6edf3writeTb4b4b4(Te6edf3contentTb4b4b4) Tb4b4b4}
Tb4b4b4}
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{ Ta5d6ff"Ta5d6ffLogs exported successfully to Tffd700${Te6edf3exportFileTb4b4b4.Te6edf3absolutePathTffd700}Ta5d6ff" Tb4b4b4}
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3javaTb4b4b4.Te6edf3ioTb4b4b4.Te6edf3IOExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3eTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffFailed to export logs to file: Tffd700${Te6edf3exportFileTb4b4b4.Te6edf3absolutePathTffd700}Ta5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3w Tb4b4b4{ Ta5d6ff"Ta5d6ffLog export aborted: user canceled file dialogTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
T8b949e// Desktop has no system logcat; surface the app's own Kermit output captured by InMemoryLogBuffer (installed at
T8b949e// startup).
Tff7b72actual Tff7b72fun Td2a8ffcaptureAppLogcatTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657String Tff7b72= Te6edf3InMemoryLogBufferTb4b4b4.Te6edf3snapshotTb4b4b4(Tb4b4b4)
Served by rngit 1.5.0 - Generated in 0.06s